package greedy;

import java.util.Arrays;

/**
 * @author : Rookie
 * @description : 贪心算法 吃饼干
 * @date : 2023/6/20
 */
public class EatCookies {

    public static void main(String[] args) {
        int[] appetite = new int[] {10,3,5,8,2};
        int[] cookies = new int[]{1,3,2,7,9};
        eat(appetite,cookies);
    }

    /**
     * 吃饼干
     * @param appetite 胃口
     * @param cookies 饼干
     */
    private static void eat(int []appetite,int []cookies) {
        Arrays.sort(appetite);
        Arrays.sort(cookies);
        int index = 0,result = 0;
        for (int j : appetite) {
            while (index < cookies.length && cookies[index] < j) {
                index++;
            }
            if (index < cookies.length) {
                result++;
            }
        }
        System.out.println(result);
    }
}
